package com.lcg.exchange.security;

import com.lcg.exchange.mapper.RoleMapper;
import com.lcg.exchange.mapper.UserMapper;
import com.lcg.exchange.model.Role;
import com.lcg.exchange.model.User;
import com.lcg.exchange.model.UserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MySecurityDataService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RoleMapper roleMapper;

    public User findUserByName(String username){
        UserExample example = new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andUserNameEqualTo(username);
        List<User> users = userMapper.selectByExample(example);
        if (users != null && users.size()>0)
            return users.get(0);
        return null;
    }

    public List<Role> findRoleListByUserId(String userId){
        return roleMapper.findRoleListByUserId(userId);
    }
}
